﻿import QtQuick 2.0
import QtGraphicalEffects 1.14

Rectangle {
    id: lightBtn
    property bool lightBtnOpened:false
    property string imageDefultSource: modelData
    property string imageLightSource: getImageSouce(imageDefultSource, 2)

    width: 128
    height: 128
    radius: 23
    color: lightBtnOpened ? "#2D8CFF" : "#272C39"
    border.width: 1
    border.color: lightBtnOpened ? "#2D8CFF" : "#44576E"
    Image{
        id: btnImg
        anchors.centerIn: parent
        source: imageDefultSource
        fillMode: Image.PreserveAspectFit
    }
    MouseArea{
        anchors.fill: parent
        onClicked: {
            lightBtnOpened = lightBtnOpened ? false : true
            lightBtn.color = lightBtnOpened ? "#2D8CFF" : "#272C39"
            lightBtn.border.color = lightBtnOpened ? "#2D8CFF" : "#44576E"
            btnImg.source = ""
            btnImg.source = lightBtnOpened ? imageLightSource : imageDefultSource
            btnClicked(lightBtnOpened)

            switch(index)
            {
                case 0:can_manager.engine_fan_reverse_switch=lightBtnOpened;break;
                case 1:can_manager.centralized_lubrication_switch=lightBtnOpened;break;
                case 2:can_manager.overload_switch=lightBtnOpened;break;
                case 3:can_manager.high_light_switch=lightBtnOpened;break;
                case 4:can_manager.dipped_headlight_switch=lightBtnOpened;break;
                case 5:can_manager.position_light_switch=lightBtnOpened;break;
                case 6:can_manager.cab_headlight_switch=lightBtnOpened;break;
                case 7:can_manager.blade_verticallight_switch=lightBtnOpened;break;
                case 8:can_manager.rearlight_switch=lightBtnOpened;break;
                case 9:can_manager.cab_rearlight_switch=lightBtnOpened;break;
                case 10:can_manager.grader_rearlight_switch=lightBtnOpened;break;
                case 11:can_manager.grader_brake=lightBtnOpened;break;
            }

        }
    }

    layer.enabled: true
    layer.effect: DropShadow {
        transparentBorder: true
        horizontalOffset: 4
        verticalOffset: 4
        spread: 0.0
    }

    function getImageSouce(source, index){
        return source.substring(0, source.lastIndexOf('.')) +"_" + String(index)+ ".png";
    }
}
